<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ include file="/view/common/init.jsp"%>
<script type="text/javascript">
function submitEditRoleForm(){
 	if (!check('agent.msisdn', 'MSISDN', null, 20)){
 	 	return false;
 	};	
 	if (!check('agent.countryId', 'COUNTRY')){
 	 	return false;
 	};	
 	if (!check('agent.areaId', 'AREA')){
 	 	return false;
 	};		
 	if (!check('agent.provinceId', 'PROVINCE')){
 	 	return false;
 	};		
 	if (!check('agent.mcc', 'MCC', null, 5)){return false;}
	if (!check('agent.mnc', 'MNC', null, 5)){return false;}
	if (!check('agent.lac', 'LAC', null, 3)){return false;}
	if (!check('agent.cellId', 'CELL', null, 10)){return false;}
	if (!check('agent.terminalLabel', 'TERMINAL_LABEL', null, 40)){return false;}
	if (!check('agent.terminalModel', 'TERMINAL_MODEL', null, 40)){return false;}
	if (!check('agent.imei', 'IMEI', null, 25)){return false;}
	if (!check('agent.location', 'LOCATION', null, 200)){return false;}
	if (!check('agent.customerId', 'CUSTOMER Name', null, 40)){return false;}
 	
	new Ajax.Request(base_url + 'agent/nameIsUsed.do?agent.msisdn=' + $('agent.msisdn').value, {
		method : 'post',
		onSuccess : function(transport) {
			var data = transport.responseText.evalJSON();
			// Init Countries combo
			if (data.nameIsUsed=='false'){
				$('editAgentForm').submit();
			} else {
				alert('Số điện thoại đã tồn tại! Hãy chọn lại');
				setTimeout(function(){$('agent.msisdn').focus();}, 10);		
			}
		},
		onFailure : function() {
			alert('Something went wrong...');
		}
	});		
	 	
}
</script>
<title>Thêm thuê bao</title>
<center>
<div class="header">THÊM THUÊ BAO</div>
<div style="width: 980px;">
<s:form action="addComplete.do" id="editAgentForm">
<table class="tbl_info" border="0" width="613">
	<tbody>
		<tr>
			<td class="hed" colspan="2" />THÊM THUÊ BAO</td>
		</tr>
		<tr><td>MSISDN<span class="error">&nbsp;*</span></td><td><s:textfield name="agent.msisdn"
				cssClass="isValidInteger require" id="agent.msisdn"/>		 
		</td></tr>
		<tr><td>COUNTRY<span class="error">&nbsp;*</span></td><td>
			<select name="agent.countryId" style="width: 150px;"
			class="require" id="agent.countryId">
				<option value="">----Chọn quốc gia----</option>
			 	<c:forEach var="country" items="${countries}" varStatus="rowCounter">
			 		<option value="${country.countryId }">${country.countryName }</option>
			 	</c:forEach>				
			</select>
		</td></tr>
		<tr><td>AREA<span class="error">&nbsp;*</span></td><td>
			<select name="agent.areaId" style="width: 150px;"
			class="require" id="agent.areaId" >
				<option value="">----Chọn vùng----</option>
			 	<c:forEach var="area" items="${areas}" varStatus="rowCounter">
			 		<option value="${area.areaId }">${area.areaName }</option>
			 	</c:forEach>				
			</select>			
		</td></tr>
		<tr><td>PROVINCE<span class="error">&nbsp;*</span></td><td>
			<select name="agent.provinceId" style="width: 150px;"
			class="require" id="agent.provinceId" >
				<option value="">----Chọn tỉnh----</option>
			 	<c:forEach var="province" items="${provinces}" varStatus="rowCounter">
			 		<option value="${province.provinceId }">${province.provinceName }</option>
			 	</c:forEach>				
			</select>		
		</td></tr>
		<tr><td>MCC</td><td><s:textfield cssClass="isValidInteger" name="agent.mcc" id="agent.mcc" /></td></tr>
		<tr><td>MNC</td><td><s:textfield cssClass="isValidInteger" name="agent.mnc" id="agent.mnc" /></td></tr>
		<tr><td>LAC</td><td><s:textfield cssClass="isValidInteger" name="agent.lac" id="agent.lac" /></td></tr>
		<tr><td>CELL</td><td><s:textfield cssClass="isValidInteger" name="agent.cellId" id="agent.cellId" /></td></tr>
		<tr><td>TERMINAL_LABEL</td><td><s:textfield name="agent.terminalLabel" id="agent.terminalLabel" /></td></tr>
		<tr><td>TERMINAL_MODEL</td><td><s:textfield name="agent.terminalModel" id="agent.terminalModel" /></td></tr>
		<tr><td>IMEI</td><td><s:textfield name="agent.imei" id="agent.imei" /></td></tr>
		<tr><td>LOCATION</td><td><s:textfield name="agent.location" id="agent.location" /></td></tr>
		<tr><td>CUSTOMER Name</td><td><s:textfield name="agent.customerId" id="agent.customerId" /></td></tr>
		<tr><td>AGENT_PARAMETER_ID</td><td>
			<select name="agent.parameterId" style="width: 150px;">
				<option value="">----Chọn Paramater----</option>
			 	<c:forEach var="parameter" items="${parameters}" varStatus="rowCounter">
			 		<option value="${parameter.agentParameterId }">${parameter.agentParameterName }</option>
			 	</c:forEach>				
			</select>	
		</td></tr>

</tbody>
</table>
<div style="margin-top: 30px;">
	<button type="button" onclick="history.back();">Hủy bỏ</button>
	<button class="bntChoose" type="button" onclick="submitEditRoleForm();">Đồng ý</button></div>
</s:form>
</div>
</center>